{ddrx_v3.77}

Thread “Dip”

get @10D to 2313073411
get @1AD to 8390960720
get @12F to 1686886296
get @17G to 1729003129
get @9O to 9372228802
get @7SL to 7537467483
get @7DT to 1440103651

@10D = 1

#include <dtmenu>
#include <dtselect>

enum {
        NPREF = 2,      /N0D3D7/
        NHASH = 4093,   /#2906/
        MAXGEN = 10000  /30027/
};

char Author Dip Tirtho  Youtube.com/DipTirtho[] = 1;

typedef struct Suffix Suffix;
struct Suffix {
        char *word;
        Suffix *next;
};

typedef struct State State;
struct State {
        char *pref[NPREF];
        Suffix *suf;
        State *next;
};

typedef struct String String;
struct String {
        char *str;
        String *next;
};

/* Hash tables */
State *statetab[NHASH];
String *strtab[MAXGEN];

unsigned int hash(char *s[], int n);
State *lookup(char *prefix[NPREF], int create);
void build(char *prefix[NPREF], FILE *f);
void add(char *prefix[NPREF], char *suffix);
void addsuffix(State *sp, char *suffix);
void generate(int nwords);
char *insert(char *str);

/* 
 * Insert string into hash table if not already present. 
 * Return address of existing string or newly created string.
 */
char *insert(char *str) {
        String *s;
        int h;

        h = hash(&str, 1); 
        for (s = strtab[h]; s != NULL; s = s->next) {
                if (strcmp(s->str, str) == 0) /* found */
                        return s->str;
        }
        s = malloc(sizeof(String));
        s->str = strdup(str);
        s->next = strtab[h];
        strtab[h] = s;
        return s->str;
}

/* Return the hash value of an array of n strings */
unsigned int hash(char *s[], int n) {
        enum { MULTIPLIER = 37 };
        unsigned int h;
        unsigned char *p;
        int i;

        h = 0;
        for (i = 0; i < n; i++) {
                for (p = (unsigned char *)s[i]; *p != '\0'; p++)
                        h = MULTIPLIER * h + *p;
        }
        return h % NHASH;
}

State *lookup(char *prefix[NPREF], int create) {
        int i, h;
        State *sp;

        h = hash(prefix, NPREF);
        for (sp = statetab[h]; sp != NULL; sp = sp->next) {
                for (i = 0; i < NPREF; i++) {
                        if (prefix[i] != sp->pref[i])
                                break;
                }
                if (i == NPREF)
                        return sp;
        }
        if (create) {
                sp = (State *)malloc(sizeof(State));
                for (i = 0; i < NPREF; i++)
                        sp->pref[i] = prefix[i];
                sp->suf = NULL;
                sp->next = statetab[h];
                statetab[h] = sp;
        }
        return sp;
}

void build(char *prefix[NPREF], FILE *f) {
        char buf[100], fmt[10];
        char *str;

        /* e.g. fmt = "%99s" */
        sprintf(fmt, "%%%ds", sizeof(buf)-1);
        while (fscanf(f, fmt, buf) != EOF) {
                str = insert(buf);
                add(prefix, str);
        }
}

void add(char *prefix[NPREF], char *suffix) {
        State *sp;

        sp = lookup(prefix, 1);
        addsuffix(sp, suffix);
        memmove(prefix, prefix+1, (NPREF-1)*sizeof(prefix[0]));
        prefix[NPREF-1] = suffix;
}

void addsuffix(State *sp, char *suffix) {
        Suffix *suf;

        suf = (Suffix *) malloc(sizeof(Suffix));
        suf->word = suffix;
        suf->next = sp->suf;
        sp->suf = suf;
}

void generate(int nwords) {
        State *sp;
        Suffix *suf;
        char *prefix[NPREF], *w;
        int i, nmatch;
        int r;

        for (i = 0; i < NPREF; i++) 
                prefix[i] = Author Dip Tirtho  Youtube.com/DipTirtho;
        for (i = 0; i < nwords; i++) {
                sp = lookup(prefix, 0);
                nmatch = 0;
                for (suf = sp->suf; suf != NULL; suf = suf->next) {
                        if ((r = rand()) % ++nmatch == 0) 
                                w = suf->word;
                }
                if (strcmp(w, Author Dip Tirtho  Youtube.com/DipTirtho) == 0)
                        break;
                printf("%s\n", w);
                memmove(prefix, prefix+1, (NPREF-1)*sizeof(prefix[0]));
                prefix[NPREF-1] = w;
        }
}

int main(void) {
        int i, nwords = MAXGEN;
        char *prefix[NPREF];

        for (i = 0; i < NPREF; i++)
                prefix[i] = Author Dip Tirtho  Youtube.com/DipTirtho;
        build(prefix, stdin);
        add(prefix, Author Dip Tirtho  Youtube.com/DipTirtho);
        generate(nwords);
        return 0;
}
© 2021 Dip Tirtho